package com.estun.backroundManagementService.modules.process.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.estun.backroundManagementService.aop.operationLog.Log;
import com.estun.backroundManagementService.aop.operationLog.LogConstants;
import com.estun.backroundManagementService.domain.BasePageRequest;
import com.estun.backroundManagementService.domain.BaseResponse;
import com.estun.backroundManagementService.modules.process.model.ProcessDetail;
import com.estun.backroundManagementService.modules.process.service.ProcessDetailService;
import com.estun.backroundManagementService.utils.QueryWrapperUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 工艺
 */
@RestController
@RequestMapping("/processDetail")
@RequiredArgsConstructor
public class ProcessDetailController {

    private final ProcessDetailService processDetailService;

    //分页查询工序信息
    @PostMapping("/page")
    public BaseResponse page(@RequestBody BasePageRequest<ProcessDetail> pageRequest) {
        Page<ProcessDetail> page = new Page<>(pageRequest.getPage(), pageRequest.getSize());
        QueryWrapper<ProcessDetail> queryWrapper = QueryWrapperUtil.buildQueryWrapper(pageRequest.getQuery());
        Page<ProcessDetail> page1 = processDetailService.page(page, queryWrapper);
        return BaseResponse.success(page1);
    }

    // 根据ID获取工序信息
    @GetMapping("/{id}")
    public BaseResponse getProcessDetailById(@PathVariable String id) {
        return BaseResponse.success(processDetailService.getById(id));
    }

    // 添加工序信息
    @PostMapping("/add")
    @Log(module = "工艺管理 新增", type = LogConstants.INSERT, desc = "工艺管理 新增")
    public BaseResponse addProcessDetail(@RequestBody ProcessDetail processDetail) {
        return BaseResponse.success(processDetailService.save(processDetail));
    }

    // 更新工序信息
    @PutMapping("/update")
    @Log(module = "工艺管理 更新", type = LogConstants.UPDATE, desc = "工艺管理 更新")
    public BaseResponse updateProcessDetail(@RequestBody ProcessDetail processDetail) {
        return BaseResponse.success(processDetailService.updateById(processDetail));
    }

    // 删除工序信息
    @DeleteMapping("/delete/{id}")
    @Log(module = "工艺管理 删除", type = LogConstants.DELETE, desc = "工艺管理 删除")
    public BaseResponse deleteProcessDetail(@PathVariable String id) {
        return BaseResponse.success(processDetailService.removeById(id));
    }


    @ApiOperation("查询所有")
    @GetMapping(value = "/list")
    @ResponseBody
    public BaseResponse list() {
        return BaseResponse.success(processDetailService.list());
    }


}
